package org.eclipse.pde.internal.ui.editor.product.customization;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.pde.core.plugin.IPluginElement;
import org.eclipse.pde.core.plugin.IPluginObject;
import org.eclipse.pde.internal.core.iproduct.ICustomizationInfo;
import org.eclipse.pde.internal.core.iproduct.ITransformationsManager;

public class ChangeNameAction extends TransformationAction {

	private TreeViewer fTreeViewer;

	public ChangeNameAction(ICustomizationInfo info, IStructuredSelection selection, TreeViewer treeViewer) {
		super("Change name", info, selection);
		fTreeViewer = treeViewer;
		Object element = selection.getFirstElement();
		ITransformationsManager tm = info.getTransformsManager();
		if (element instanceof IPluginElement && !tm.isAffected((IPluginObject) element)) {
			setEnabled(((IPluginElement) element).getAttribute(IPluginObject.P_NAME) != null);
		} else
			setEnabled(false);
	}

	public void run() {
		fTreeViewer.editElement(fSelection.getFirstElement(), 0);
	}

}
